<?php
/**
 * Stack implementation
 *
 * @version $Id: Stack.php,v 1.2 2011-05-06 05:18:54 herve Exp $
 * @copyright 2011
 */
class Stack {
	/** 
	* @var array The Stack data. 
	* @access private 
	*/
	var $_stack= array ();

	/** 
	* Push the argument onto the stack. 
	* @param mixed $content The element to be pushed onto the stack. 
	*/
	function push($element) {
		array_push($this->_stack, & $element);
	}

	/** 
	* Push the objects contains in array argument onto the stack. 
	* @param mixed $elements The element to be pushed onto the stack. 
	*/
	function push_all($elements) {
		if (is_array($elements)) {
			foreach ($elements as $element)
				$this->push($element);
		}
	}

	/** 
	* Pop the Stack. 
	* @returns mixed The reference to the popped element. 
	*/
	function & pop() {
		$element= & $this->top();
		array_pop($this->_stack);
		return $element;
	}

	/** 
	* Returns a reference to the top of the stack. 
	* @returns mixed A reference to the top of the stack. 
	*/
	function & top() {
		$count= count($this->_stack);
		// Prevent bad reference pointer 
		if ($count == 0) {
			return null;
		}
		return $this->_stack[count($this->_stack) - 1];
	}

	/** 
	* Get the lenght of the Stack. 
	* @returns int The lenght of the Stack. 
	*/
	function get_length() {
		return count($this->_stack);
	}
	
	function is_empty(){
		return $this->get_length() <= 0;
	}
}

?>
